import QtQuick
import QtQuick.Controls
import Tools 1.0

Page {
    title: "Guide"
    Component.onCompleted: {
        console.log("Guide page loaded")
    }
    // 添加返回按钮
    Button {
        id: backButton
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.margins: 5
        visible: stackView.depth > 1
        z: 1
        width: 80
        height: 45
        text: "Home"
        onClicked: goBack()
    }

    StackView {
        id: stackView
        anchors.fill: parent
        anchors.topMargin: depth > 1 ? 48 : 0
        initialItem: Page {
            title: "Home"
            Grid {
                anchors.centerIn: parent
                spacing: 20
                GuideButton { // 参考天线：Reference Antenna 移动站：Rover Unit
                    title: "RA RU Pairing"
                    icon: 'qrc:/icons/signal.svg'
                    description: "This is button 1"
                    onClicked: {
                        console.log("RA RU Pairing clicked")
                        stackView.push(toolRaPairComponent)
                    }
                }

                GuideButton {
                    title: "Mower Client"
                    icon: "⭐"
                    description: "Mower client tool"
                    onClicked: {
                        console.log("Button 1 clicked")
                        stackView.push(mowerClientComponent)
                    }
                }

                GuideButton {
                    title: "SerialPort"
                    icon: "qrc:/icons/wait.png"
                    description: "serial port tool"
                    onClicked: {
                        console.log("Button 1 clicked")
                    }
                }

                GuideButton {
                    title: "Flash Tool"
                    icon: "qrc:/icons/wait.png"
                    description: "This is button 2"
                    onClicked: {
                        console.log("flash Tool clicked")
                        stackView.push(flashToolComponent)
                    }
                }
                GuideButton {
                    title: "Check"
                    icon: "qrc:/icons/wait.png"
                    description: "This is button 2"
                    onClicked: {
                        console.log("Button 1 clicked")
                    }
                }
            }
        }
    }

    // RA 配对
    Component {
        id: toolRaPairComponent
        ToolRaPair { 
        }
    }

    // 割草机客户端
    Component {
        id: mowerClientComponent
        MowerClient { 
        }
    }

    // Flash Tool
    Component {
        id: flashToolComponent
        FlashToolView { 
        }
    }   

    function goBack() {
        stackView.pop()
    }
}